package health.lm.com.find.pop;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.arouter.launcher.ARouter;

import health.lm.com.component_base.widget.CustomPopWindow;
import health.lm.com.component_base.widget.RatingBar;
import health.lm.com.find.R;
import health.lm.com.find.model.ExperienceModel;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.router.ARouterConstant;

/**
 * @author GQI
 * @description: 评价
 * @date :2019-08-14 14:08
 */
public class EvaluationPopUtil {
    public static EvaluationPopUtil upLevelPopUtil;
    private CustomPopWindow popWindow;
    private int nr;
    private int zl;
    private int lc;
    private int jz;
    private int fwzl;
    private int cyd;

    private EvaluationPopUtil() {
    }

    public static EvaluationPopUtil getInstance(){
        if (null == upLevelPopUtil) {
            upLevelPopUtil = new EvaluationPopUtil();
        }
        return upLevelPopUtil;
    }

    /**
     * 显示popwindow
     */
    public void init(Context context, View mLayoutPopup, String id) {
        View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_evaluation, null);
        contentView.findViewById(R.id.rl_main).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                popWindow.dissmiss();
            }
        });
        //活动内容
        ((RatingBar)contentView.findViewById(R.id.rb_hd)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        nr = (int) RatingCount;
                    }
                }
        );
        //活动质量
        ((RatingBar)contentView.findViewById(R.id.rb_zl)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        zl = (int) RatingCount;
                    }
                }
        );
        //活动流程
        ((RatingBar)contentView.findViewById(R.id.rb_lc)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        lc = (int) RatingCount;
                    }
                }
        );
        //活动价值
        ((RatingBar)contentView.findViewById(R.id.rb_jz)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        jz = (int) RatingCount;
                    }
                }
        );
        //服务质量
        ((RatingBar)contentView.findViewById(R.id.rb_fwzl)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        fwzl = (int) RatingCount;
                    }
                }
        );
        //再次参与度
        ((RatingBar)contentView.findViewById(R.id.rb_cyd)).setOnRatingChangeListener(
                new RatingBar.OnRatingChangeListener() {
                    @Override
                    public void onRatingChange(float RatingCount) {
                        cyd = (int) RatingCount;
                    }
                }
        );
        //确定
        contentView.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dissmiss();
                ExperienceModel.getInstance().evaluationPop(id, nr, zl, lc, jz, fwzl, cyd, new SimpleCallBack<Object>() {
                    @Override
                    public void onSuccess(Object o) {
                        ARouter.getInstance().build(ARouterConstant.EvaluationSuccessActivity).navigation();
                    }
                });

            }
        });
        popWindow = new CustomPopWindow.PopupWindowBuilder(context)
                .setView(contentView)
                .enableBackgroundDark(true)
                .setBgDarkAlpha(0.3f)
                .setOutsideTouchable(true)
                .setAnimationStyle(R.style.pop_bottom_anim)
                .size(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)//显示大小
                .create()
                .showAtLocation(mLayoutPopup, Gravity.CENTER, 0, 0);
    }
}
